<?
require_once("/var/www/html/new/com.inc.php");
include('../../jq/com/errBack.php');
include("../class/ProductInfo.php");
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$pid = $_REQUEST['pid'] + 0;

$orderMonth = $_REQUEST['orderMonth'];// 需要获取的月份价格
$monthStart = $orderMonth."-01";
$monthEnd = $orderMonth."-".date("t",strtotime($monthStart));


$p = new ProductInfo($s,$pid);

// 获取产品类型
$sql = "select l.id,l.p_type from uu_land l left join uu_products p on p.contact_id=l.id where p.id=$pid limit 1";
$GLOBALS['le']->query($sql);
$GLOBALS['le']->fetch_assoc();
$type = $GLOBALS['le']->f('p_type');
if($type=='F'){// 套票获取有效期
	include_once("/var/www/html/new/d/class/PackTicket.class.php");
	$lid = $GLOBALS['le']->f('id');
	$pack = new PackTicket($lid);
	$useDate = $pack->useDate();
	$mintime = substr($useDate['sDate'],0, 10);// 有效开始时间
	$maxtime = $useDate['mDate'] ? $useDate['mDate']:'2020-10-10';// 有效结束时间
	
	// 使用开始时间大于结束时间或查看的月份大于最大月份，套票无效
	if($useDate['sDate']>$useDate['eDate']  || (strtotime($monthStart) > strtotime($maxtime)) ){ 
		$data["pricelists"] = array();
		$data["about"]["mintime"] = strtotime($mintime);
		$data["about"]["maxtime"] = strtotime($maxtime);
		echo json_encode($data);
		exit;
	}
	if($useDate['mDate']!='') $endtime = substr($useDate['mDate'],0, 10);
}else{
	$mintime=$p->getMinValidTime();
	$maxtime=$p->getMaxValidTime();
	$begintime = $mintime;
	$endtime   = $monthEnd;
}
if($begintime<$monthStart) $begintime = $monthStart;





// $days=(strtotime($endtime)-strtotime($begintime))/24/3600;
$jsonData=array();

//TODO::获取差价
$aid = intval($_GET['aid']);
$sql = "SELECT apply_did FROM uu_products WHERE id=$pid LIMIT 1";
$GLOBALS['le']->query($sql);
$GLOBALS['le']->fetch_assoc();
$said = $GLOBALS['le']->f('apply_did');
if ($said==$aid) {
    $aid = 0;
}
$unLogin = true;



$ac = $_SESSION['saccount'];

if (isset($_SESSION['dtype'])) {
    $ptype = ($_SESSION['dtype']==0 || $_SESSION['dtype']==1 || $_SESSION['dtype']==6) ? 0 : 1;
} else {
    $ptype = 1;
}

if (isset($_SESSION['saccount']) ) {
    $ac = $_SESSION['saccount'];
} else {
    $sql = "SELECT account FROM pft_member WHERE id='{$_SESSION['apply_did']}' LIMIT 1";
    $GLOBALS['le']->query($sql);
    $GLOBALS['le']->fetch_assoc();
    $ac = $GLOBALS['le']->f('account');
}
// echo $begintime,'---', $endtime,'---', $ac,'---', $ptype,'---', $aid;

$prices=$p->getPeriodPrice($begintime, $endtime, $ac, $ptype, $aid);
foreach($prices as $date=>$price){
	$tprice=$price['sprice']+$dprice;
	if($unLogin || $_SESSION['dtype']==5){
		$tprice=$price['lprice'];
	}	
	$jsonData[]=array(
        "date"=>$date,
        "price"=>$tprice/100,
        "storage"=>$price['storage']
    );
}
$data["pricelists"]=$jsonData;
$data["about"]["mintime"]=strtotime($mintime);
$data["about"]["maxtime"]=strtotime($maxtime);
if($_REQUEST['datatype']=="jsonp"){
	echo $_REQUEST['callback']."(".json_encode($data).")";
}else{
	echo json_encode($data);
}
?>